package com.safeneeds.linguimana.web;

import java.util.List;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import com.safeneeds.linguimana.dto.NoticeDataStorePort;
import com.safeneeds.linguimana.entity.PortGlutNotice;
import com.safeneeds.linguimana.ser.IBgNoticeService;
import com.safeneeds.util.base.BaseAction;
import com.safeneeds.util.base.IUserInfo;
import com.safeneeds.util.base.RetType;
import com.safeneeds.util.other.StringUtil;
import com.safeneeds.util.page.PageInfo;
/**
 * 门户新闻管理
 * @author zqq
 * @date 2017年2月21日
 * desc:用于处理通知公告请求
 */
@Controller
@RequestMapping("bgPortGlutNotice")
public class BgGlutNoticeAction extends BaseAction {

	@Resource(name="bgNoticeService")
	private IBgNoticeService bgNoticeService;
	
	
	
	@RequestMapping("listNotice.do")
	public String listNotice(ModelMap modelMap,PageInfo pageInfo, NoticeDataStorePort noticedataStore){
		
		//相应页面搜索按钮
		if(noticedataStore!= null){
			
			//获取分页数据
			pageInfo = bgNoticeService.listNoticePage(pageInfo, noticedataStore);
			System.out.println(pageInfo);
			System.out.println(noticedataStore);
		}

		modelMap.put("pageInfo", pageInfo);
		modelMap.put("noticedataStore", noticedataStore);
		
		return getViewsModelPathSys("portmana/bg/glutnotice/noticeList"); 
	}
	/**
	 * 新增/编辑通知公告登录
	 * 
	 * @return
	 */
	@RequestMapping("addNoticeLogin.do")
	public String addNoticeLogin(ModelMap modelMap, PortGlutNotice portGlutNotice, NoticeDataStorePort noticedataStore){
		System.out.println("3434354311111111111111111111111111111111111111111");
		
		modelMap.put("noticedataStore", noticedataStore);
		//相应编辑按钮获取NoticeId这条通知公告信息
		if(portGlutNotice != null && !StringUtil.isEmpty(portGlutNotice.getNoticeId())){
			//获取新闻信息
			portGlutNotice = bgNoticeService.getNoticeById(portGlutNotice.getNoticeId());
			
			modelMap.put("notice", portGlutNotice);
			
		}
		return getViewsModelPathSys("portmana/bg/glutnotice/editNotice");
	}
	/**
	 * 添加、更新通知公告
	 * @return
	 */
	@RequestMapping("addNotice.do")
	public String addNotice(HttpServletRequest request, ModelMap modelMap, PortGlutNotice portGlutNotice, NoticeDataStorePort noticedataStore, RedirectAttributes attr){
		IUserInfo userInfo = getUserInfo(request);
		System.out.println(portGlutNotice.toString());
		bgNoticeService.addOrEditNotice(portGlutNotice, noticedataStore, userInfo);	
		return "redirect:/bgPortGlutNotice/listNotice.do";
	}
	
	/**
	 * 通知公告详情
	 * @param modelMap
	 * @return
	 */
	
	@RequestMapping("noticeDetail.do")
	public String addNoticeLogin(ModelMap modelMap, PortGlutNotice portGlutNotice){
		//获取新闻信息
		portGlutNotice = bgNoticeService.getNoticeById(portGlutNotice.getNoticeId());

		modelMap.put("notice", portGlutNotice);
		return getViewsModelPathSys("portmana/bg/glutnotice/noticeDetail");
	}
	
	@ResponseBody
	@RequestMapping("updateNoticeIsShow.ido")
	public RetType updateNoticeIsShow(String ids,String isShow){
		//System.out.println(nameIsShow);
		System.out.println(ids+"mmm隐藏或发布mmmm"+isShow);
		RetType reType = new RetType();
		int temp = bgNoticeService.updateNoticeShow(ids,isShow);
		if(temp>0){
			System.out.println("temp+++++++++");
			reType.setErrCode("1");
		}else{
			reType.setErrCode("2");
		}
		
		return reType;
	} 
}
